// 导入Cupertino组件库，包含iOS样式的UI组件
import 'package:flutter/cupertino.dart';
// 导入Flutter Material组件库，包含基础UI组件
import 'package:flutter/material.dart';
// 导入ScreenUtil组件库，用于屏幕适配
import 'package:flutter_screenutil/flutter_screenutil.dart';
// 导入OkToast组件库，用于显示Toast
import 'package:oktoast/oktoast.dart';
// 导入入口文件
import 'package:demo/pages/index.dart';

// 设计尺寸
Size get designSize {
  // 获取第一个视图的尺寸
  final firstView = WidgetsBinding.instance.platformDispatcher.views.first;
  // 逻辑短边
  final logicalShortestSide =
      firstView.physicalSize.shortestSide / firstView.devicePixelRatio;
  // 逻辑长边
  final logicalLongestSide =
      firstView.physicalSize.longestSide / firstView.devicePixelRatio;
  // 逻辑尺寸
  // final logicalSize = Size(logicalLongestSide, logicalShortestSide);
  // 设计尺寸
  // final designSize = logicalSize / firstView.devicePixelRatio;
  // 缩放比例
  final scaleFactor = 0.95;
  return Size(
    logicalLongestSide * scaleFactor,
    logicalShortestSide * scaleFactor,
  );
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    // toast提示必须为App的顶层组件
    return OKToast(
      // 适配父组件
      child: ScreenUtilInit(
        designSize: designSize,
        builder: (context, child) {
          // 适配子组件
          return MaterialApp(
            title: '蜗牛工具箱',
            theme: ThemeData(
              // 应用程序的主题配置
              colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
              useMaterial3: true,
            ),
            home: const MainHome(),
          );
        },
      ),
    );
  }
}
